define(function(require, exports, module) {
  var lang = require('lang'),
      common = require('common');

  var setTitle = function(title) {
    $(document).find('title').text(title);
  };

  var app = {
    form: require('main/user/view/form'),
    template: {
      signin: require('main/user/tpl/login-form.handlebars'),
      signup: require('main/user/tpl/register-form.handlebars'),
      reset: require('main/user/tpl/reset-form.handlebars'),
      activate: require('main/user/tpl/activate-form.handlebars')
    }
  };

  module.exports = Backbone.Router.extend({
    routes: {
      '': 'loginPage',
      'signin': 'loginPage',
      'signup': 'registerPage',
      'reset': 'resetPage',
      'activate': 'activatePage'
    },
    currentApp: null,
    initialize: function() {},
    loginPage: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.form({
        captcha: true,
        template: app.template.signin
      });
      setTitle(lang.get('user') + lang.get('signin'));
    },
    registerPage: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.form({
        captcha: true,
        template: app.template.signup
      });
      setTitle(lang.get('user') + lang.get('signup'));
    },
    resetPage: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.form({
        captcha: true,
        template: app.template.reset
      });
      setTitle(lang.get('reset') + lang.get('password'));
    },
    activatePage: function() {
      if(this.currentApp) this.currentApp.undelegateEvents();
      this.currentApp = app.form({
        captcha: true,
        template: app.template.activate
      });
      setTitle(lang.info('101'));
    }
  });
});